package com.buildings.activity.table;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.buildings.R;
import com.buildings.api.Api;
import com.buildings.api.Constant;
import com.buildings.base.BaseActivity;
import com.buildings.base.BaseApplication;
import com.buildings.base.JsonBean;
import com.buildings.bean.CreaterDbEntity;
import com.buildings.bean.CreaterEntity;
import com.buildings.bean.FaultTypeBean;
import com.buildings.bean.GeomorphySvyReProfDbEntity;
import com.buildings.bean.LoginBean;
import com.buildings.bean.SamplePointEntity;
import com.buildings.http.BaseCallBack;
import com.buildings.http.JsonBuilder;
import com.buildings.http.MyHttpClient;
import com.buildings.util.CustomToast;
import com.buildings.util.DialogUtils;
import com.buildings.util.FileUtil;
import com.buildings.util.HYDialogUtils;
import com.buildings.util.HYImageUtils;
import com.buildings.util.PhotoRecycleBuild;
import com.buildings.util.SPUtil;
import com.buildings.util.StringUtil;
import com.buildings.util.TabTitleBuilder;
import com.buildings.view.ShowBottomDialog;
import com.google.gson.Gson;
import com.zr.earthquate.db.greendao.DaoSession;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

//火山口-点
public class CraterActivity extends BaseActivity {
    @BindView(R.id.ll_tab_title)
    LinearLayout llTabTitle;
    @BindView(R.id.rv_pics)
    RecyclerView rvPics;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right_text)
    TextView tvRightText;
    @BindView(R.id.et_id)
    EditText etId;
    @BindView(R.id.et_conename)
    EditText etConename;
    @BindView(R.id.et_conetype)
    EditText etConetype;
    @BindView(R.id.et_conemorphology)
    EditText etConemorphology;
    @BindView(R.id.et_coneheight)
    EditText etConeheight;
    @BindView(R.id.et_craterdepth)
    EditText etCraterdepth;
    @BindView(R.id.et_insideslopeangle)
    EditText etInsideslopeangle;
    @BindView(R.id.et_outsideslopeangle)
    EditText etOutsideslopeangle;
    @BindView(R.id.tv_overfalldirection)
    TextView tvOverfalldirection;
    @BindView(R.id.et_deposittype)
    EditText etDeposittype;
    @BindView(R.id.et_depositgranularity)
    EditText etDepositgranularity;
    @BindView(R.id.et_lavadribletsize)
    EditText etLavadribletsize;
    @BindView(R.id.et_rockinclusiontype)
    EditText etRockinclusiontype;
    @BindView(R.id.et_rockinclusionnum)
    EditText etRockinclusionnum;
    @BindView(R.id.et_rockinclusiongranularity)
    EditText etRockinclusiongranularity;
    @BindView(R.id.et_rockinclusionshape)
    EditText etRockinclusionshape;
    @BindView(R.id.et_rockinclusionoutputstate)
    EditText etRockinclusionoutputstate;
    @BindView(R.id.et_photoAiid)
    EditText etPhotoAiid;
    @BindView(R.id.et_photodescArwid)
    EditText etPhotodescArwid;
    @BindView(R.id.et_photographer)
    EditText etPhotographer;
    @BindView(R.id.et_remark)
    EditText etRemark;
    @BindView(R.id.et_bottomdiameter)
    EditText etBottomdiameter;
    @BindView(R.id.et_craterwallsdiameter)
    EditText etCraterwallsdiameter;
    @BindView(R.id.et_craterdiameter)
    EditText etCraterdiameter;
    @BindView(R.id.et_depositthickness)
    EditText etDepositthickness;
    @BindView(R.id.ll_visibile)
    LinearLayout llVisibile;
    @BindView(R.id.btn_submit)
    Button btnSubmit;
    @BindView(R.id.tv_visibile)
    TextView tvVisibile;
    private String urlArr;
    private TabTitleBuilder tabTitleBuilder;
    private PhotoRecycleBuild photoRecycleBuild;
    private Dialog myDialog;
    private DaoSession daoSession;
    //断层性质数据
    private List<FaultTypeBean.DataBean> dataBeans = new ArrayList<>();
    //断层性质选中的数据
    private FaultTypeBean.DataBean dataBean;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crater);
        ButterKnife.bind(this);
        daoSession = BaseApplication.getInstance().getDaoSession();
        tabTitleBuilder = new TabTitleBuilder(llTabTitle, this);
        initView();
    }

    private String type;
    private String taskId = "";
    private String projectId = "";
    private String projectName = "";
    private String taskName = "";
    private boolean isOnline;
    //joninType 1 保存 2 详情
    private int joninType;
    private String uuid;
    private long _id = -1;

    public void initView() {
        joninType = getIntent().getIntExtra("joninType", 1);
        photoRecycleBuild = new PhotoRecycleBuild(this, rvPics, joninType);
        if (joninType != 2) {
            tvTitle.setText("火山口-点");
            tvRightText.setText("保存");
            double x = getIntent().getDoubleExtra("x", 0.0);
            double y = getIntent().getDoubleExtra("y", 0.0);
            type = getIntent().getStringExtra("type");
            taskId = getIntent().getStringExtra("taskId");
            projectId = getIntent().getStringExtra("projectId");
            projectName = getIntent().getStringExtra("projectName");
            taskName = getIntent().getStringExtra("taskName");
            isOnline = getIntent().getBooleanExtra("isOnLine", true);
            if (TextUtils.isEmpty(type)) {
                finish();
            }
            if (isOnline && TextUtils.isEmpty(taskId)){
                finish();
            }
            if (isOnline && TextUtils.isEmpty(projectId)){
                finish();
            }
            tabTitleBuilder.setLat(x);
            tabTitleBuilder.setLon(y);
            if (getIntent().hasExtra("_id")) {
                _id = getIntent().getLongExtra("_id", -1);
                setLocalData(_id);
            }
            if (1 == Constant.IS_ON_LINE){
                btnSubmit.setVisibility(View.VISIBLE);
            }else {
                btnSubmit.setVisibility(View.GONE);
            }
        } else {
            isOnline = getIntent().getBooleanExtra("isOnLine", false);
            if (1 == Constant.IS_ON_LINE){
                tvTitle.setText("火山口-点详情");
                uuid = getIntent().getStringExtra("uuid");
                tabTitleBuilder.setEnabled();
                setEnableFalse();
                getDetailHttp();
                btnSubmit.setVisibility(View.GONE);
            }else {
                tvTitle.setText("火山口-点详情");
                tvRightText.setText("保存");
                uuid = getIntent().getStringExtra("uuid");
                if (getIntent().hasExtra("_id")) {
                    _id = getIntent().getLongExtra("_id", -1);
                    setLocalData(_id);
                }
                btnSubmit.setVisibility(View.GONE);
            }
        }
    }

    public void setLocalData(long a) {
        if (a == -1) {
            return;
        }
        List<CreaterDbEntity> students = daoSession.loadAll(CreaterDbEntity.class);
        for (CreaterDbEntity createrDbEntity : students) {
            if (a == createrDbEntity.get_id()) {
                setDetail(createrDbEntity);
            }
        }
    }

    private void setEnableFalse() {
        etId.setEnabled(false);
        etConename.setEnabled(false);
        etConetype.setEnabled(false);
        etConemorphology.setEnabled(false);
        etConeheight.setEnabled(false);
        etCraterdepth.setEnabled(false);
        etInsideslopeangle.setEnabled(false);
        etOutsideslopeangle.setEnabled(false);
        tvOverfalldirection.setEnabled(false);
        etDeposittype.setEnabled(false);
        etDepositgranularity.setEnabled(false);
        etLavadribletsize.setEnabled(false);
        etRockinclusiontype.setEnabled(false);
        etRockinclusionnum.setEnabled(false);
        etRockinclusiongranularity.setEnabled(false);
        etRockinclusionshape.setEnabled(false);
        etRockinclusionoutputstate.setEnabled(false);
        etPhotoAiid.setEnabled(false);
        etPhotodescArwid.setEnabled(false);
        etPhotographer.setEnabled(false);
        etRemark.setEnabled(false);
        etBottomdiameter.setEnabled(false);
        etCraterwallsdiameter.setEnabled(false);
        etCraterdiameter.setEnabled(false);
        etDepositthickness.setEnabled(false);
    }

    @OnClick({R.id.iv_back, R.id.tv_right_text, R.id.tv_visibile, R.id.tv_overfalldirection
            ,R.id.btn_submit,R.id.iv_id_hint})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_visibile:
                if (llVisibile.getVisibility() == View.VISIBLE) {
                    llVisibile.setVisibility(View.GONE);
                    tvVisibile.setText("显示更多");
                } else {
                    llVisibile.setVisibility(View.VISIBLE);
                    tvVisibile.setText("隐藏更多");
                }
                break;
            case R.id.tv_overfalldirection:
                FaultTypeBean faultTypeBean2 = new Gson().fromJson(JsonBean.CVD_16_Direction, FaultTypeBean.class);
                setFaultTypeCVD(faultTypeBean2, "CVD-16-Direction");
                break;
            case R.id.tv_right_text:
                //TODO 调用保存表单接口
                save();
                break;
            case R.id.btn_submit:
                submit();
                break;
            case R.id.iv_id_hint:
                HYDialogUtils.showCommonAlertDialog(this, "长度17位，前9位，行政区划代码6位+3位专题号，后8位自定义编码，字母数字均可，不足8位#补齐\n" +
                                "3位专题号，用户自己设置。一般就是100，101，102...,201,202"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
        }
    }

    private void save() {
        CreaterDbEntity bean = new CreaterDbEntity();
        String province = tabTitleBuilder.getProvinceStr();
        String city = tabTitleBuilder.getCityStr();
        String area = tabTitleBuilder.getAreaStr();
        String lat = tabTitleBuilder.getLatStr();
        String lon = tabTitleBuilder.getLonStr();
        String buildingAddress = tabTitleBuilder.getBuilderAdressStr();
        String id = etId.getText().toString().trim();
        String conename = etConename.getText().toString().trim();
        String conetype = etConetype.getText().toString().trim();
        String conemorphology = etConemorphology.getText().toString().trim();
        String coneheight = etConeheight.getText().toString().trim();
        String craterdepth = etCraterdepth.getText().toString().trim();
        String insideslopeangle = etInsideslopeangle.getText().toString().trim();
        String outsideslopeangle = etOutsideslopeangle.getText().toString().trim();
        String overfalldirection = tvOverfalldirection.getText().toString().trim();
        String deposittype = etDeposittype.getText().toString().trim();
        String depositgranularity = etDepositgranularity.getText().toString().trim();
        String lavadribletsize = etLavadribletsize.getText().toString().trim();
        String rockinclusiontype = etRockinclusiontype.getText().toString().trim();
        String rockinclusionnum = etRockinclusionnum.getText().toString().trim();
        String rockinclusiongranularity = etRockinclusiongranularity.getText().toString().trim();
        String rockinclusionshape = etRockinclusionshape.getText().toString().trim();
        String rockinclusionoutputstate = etRockinclusionoutputstate.getText().toString().trim();
        String photoAiid = etPhotoAiid.getText().toString().trim();
        String photodescArwid = etPhotodescArwid.getText().toString().trim();
        String photographer = etPhotographer.getText().toString().trim();
        String remark = etRemark.getText().toString().trim();
        String bottomdiameter = etBottomdiameter.getText().toString().trim();
        String craterwallsdiameter = etCraterwallsdiameter.getText().toString().trim();
        String craterdiameter = etCraterdiameter.getText().toString().trim();
        String depositthickness = etDepositthickness.getText().toString().trim();
        if (TextUtils.isEmpty(province)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(city)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(area)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(lon)) {
            Toast("请录入纬度");
            return;
        }
        if (TextUtils.isEmpty(lat)) {
            Toast("请录入经度");
            return;
        }
        if (TextUtils.isEmpty(buildingAddress)) {
            Toast("请录入详细地址");
            return;
        }
        if (TextUtils.isEmpty(id)) {
            Toast("请录入火山口编号");
            return;
        }
        if (id.length() != 17){
            Toast("请录入正确的火山口编号");
            return;
        }
        bean.setProvince(province);
        bean.setCity(city);
        bean.setArea(area);
        bean.setLat(lat);
        bean.setLon(lon);
        bean.setTown(buildingAddress);
        bean.setId(id);
        bean.setConename(conename);
        bean.setConetype(conetype);
        bean.setConemorphology(conemorphology);
        bean.setConeheight(coneheight);
        bean.setCraterdepth(craterdepth);
        bean.setInsideslopeangle(insideslopeangle);
        bean.setOutsideslopeangle(outsideslopeangle);
        bean.setOverfalldirection(null == dataBean ?
                null == createrDbEntity ?"":createrDbEntity.getOverfalldirection() : dataBean.getDictItemCode());
        bean.setOverfalldirectionName(overfalldirection);
        bean.setDeposittype(deposittype);
        bean.setDepositgranularity(depositgranularity);
        bean.setLavadribletsize(lavadribletsize);
        bean.setRockinclusiontype(rockinclusiontype);
        bean.setRockinclusionnum(rockinclusionnum);
        bean.setRockinclusiongranularity(rockinclusiongranularity);
        bean.setRockinclusionshape(rockinclusionshape);
        bean.setRockinclusionoutputstate(rockinclusionoutputstate);
        bean.setPhotoAiid(photoAiid);
        bean.setPhotodescArwid(photodescArwid);
        bean.setPhotographer(photographer);
        bean.setCommentInfo(remark);
        bean.setBottomdiameter(bottomdiameter);
        bean.setCraterwallsdiameter(craterwallsdiameter);
        bean.setCraterdiameter(craterdiameter);
        bean.setDepositthickness(depositthickness);
        if (Constant.IS_ON_LINE == 1){
            bean.setProjectId(projectId);
            bean.setProjectName(projectName);
            bean.setTaskName(taskName);
            bean.setTaskId(taskId);
        }
        if (photoRecycleBuild.getSrcList().size() != 0) {
            String url = "";
            for (int i = 0; i < photoRecycleBuild.getSrcList().size(); i++) {
                if (TextUtils.isEmpty(url)) {
                    url = FileUtil.uriToFile(photoRecycleBuild.getSrcList().get(i), activity).getPath();
                } else {
                    url = url + "," + FileUtil.uriToFile(photoRecycleBuild.getSrcList().get(i), activity).getPath();
                }
            }
            bean.setExtends7(url);
        }
        if (-1 != _id) {
            bean.set_id(_id);
        }
        daoSession.insertOrReplace(bean);
        CustomToast.showToast(this, "保存成功");
        finish();
    }

    public void submit() {
        String province = tabTitleBuilder.getProvinceStr();
        String city = tabTitleBuilder.getCityStr();
        String area = tabTitleBuilder.getAreaStr();
        String lat = tabTitleBuilder.getLatStr();
        String lon = tabTitleBuilder.getLonStr();
        String buildingAddress = tabTitleBuilder.getBuilderAdressStr();

        String id = etId.getText().toString().trim();
        String conename = etConename.getText().toString().trim();
        String conetype = etConetype.getText().toString().trim();
        String conemorphology = etConemorphology.getText().toString().trim();
        String coneheight = etConeheight.getText().toString().trim();
        String craterdepth = etCraterdepth.getText().toString().trim();
        String insideslopeangle = etInsideslopeangle.getText().toString().trim();
        String outsideslopeangle = etOutsideslopeangle.getText().toString().trim();
        String overfalldirection = tvOverfalldirection.getText().toString().trim();
        String deposittype = etDeposittype.getText().toString().trim();
        String depositgranularity = etDepositgranularity.getText().toString().trim();
        String lavadribletsize = etLavadribletsize.getText().toString().trim();
        String rockinclusiontype = etRockinclusiontype.getText().toString().trim();
        String rockinclusionnum = etRockinclusionnum.getText().toString().trim();
        String rockinclusiongranularity = etRockinclusiongranularity.getText().toString().trim();
        String rockinclusionshape = etRockinclusionshape.getText().toString().trim();
        String rockinclusionoutputstate = etRockinclusionoutputstate.getText().toString().trim();
        String photoAiid = etPhotoAiid.getText().toString().trim();
        String photodescArwid = etPhotodescArwid.getText().toString().trim();
        String photographer = etPhotographer.getText().toString().trim();
        String remark = etRemark.getText().toString().trim();
        String bottomdiameter = etBottomdiameter.getText().toString().trim();
        String craterwallsdiameter = etCraterwallsdiameter.getText().toString().trim();
        String craterdiameter = etCraterdiameter.getText().toString().trim();
        String depositthickness = etDepositthickness.getText().toString().trim();

        if (TextUtils.isEmpty(province)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(city)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(area)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(lon)) {
            Toast("请录入纬度");
            return;
        }
        if (TextUtils.isEmpty(lat)) {
            Toast("请录入经度");
            return;
        }
        if (TextUtils.isEmpty(buildingAddress)) {
            Toast("请录入详细地址");
            return;
        }
        if (TextUtils.isEmpty(id)) {
            Toast("请录入火山口编号");
            return;
        }
        if (id.length() != 17){
            Toast("请录入正确的火山口编号");
            return;
        }
        if (myDialog == null) {
            myDialog = DialogUtils.showRefreshDialog(activity);
        } else {
            myDialog.show();
        }
        DialogUtils.showIOSDialog(activity, "提示", "", "", "", ""
                , new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (null != myDialog)
                            myDialog.dismiss();
                    }
                }, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        submit();
                        photoRecycleBuild.submitImage(photoRecycleBuild.getSrcList(), 1, new PhotoRecycleBuild.ImageCallBack() {
                            @Override
                            public void onCallBack(String url) {
                                CraterActivity.this.urlArr = url;
                                JsonBuilder jsonBuilder = new JsonBuilder(CraterActivity.this);
                                jsonBuilder.put("province", province);
                                jsonBuilder.put("city", city);
                                jsonBuilder.put("area", area);
                                jsonBuilder.put("lat", lon);
                                jsonBuilder.put("lon", lat);
                                jsonBuilder.put("town", buildingAddress);
                                jsonBuilder.put("type", type);
                                jsonBuilder.put("taskId", taskId);
                                jsonBuilder.put("projectId", projectId);
                                jsonBuilder.put("projectName", projectName);
                                jsonBuilder.put("taskName", taskName);
                                jsonBuilder.put("userId", SPUtil.get("userId", ""));
                                jsonBuilder.put("id", id);
                                jsonBuilder.put("conename", conename);
                                jsonBuilder.put("conetype", conetype);
                                jsonBuilder.put("conemorphology", conemorphology);
                                jsonBuilder.put("coneheight", coneheight);
                                jsonBuilder.put("craterdepth", craterdepth);
                                jsonBuilder.put("insideslopeangle", insideslopeangle);
                                jsonBuilder.put("outsideslopeangle", outsideslopeangle);
                                jsonBuilder.put("overfalldirection", null == dataBean ?
                                        null == createrDbEntity ?"":createrDbEntity.getOverfalldirection() : dataBean.getDictItemCode());
                                jsonBuilder.put("overfalldirectionName", overfalldirection);
                                jsonBuilder.put("deposittype", deposittype);
                                jsonBuilder.put("depositgranularity", depositgranularity);
                                jsonBuilder.put("lavadribletsize", lavadribletsize);
                                jsonBuilder.put("rockinclusiontype", rockinclusiontype);
                                jsonBuilder.put("rockinclusionnum", rockinclusionnum);
                                jsonBuilder.put("rockinclusiongranularity", rockinclusiongranularity);
                                jsonBuilder.put("rockinclusionshape", rockinclusionshape);
                                jsonBuilder.put("rockinclusionoutputstate", rockinclusionoutputstate);
                                jsonBuilder.put("photoAiid", photoAiid);
                                jsonBuilder.put("photodescArwid", photodescArwid);
                                jsonBuilder.put("photographer", photographer);
                                jsonBuilder.put("commentInfo", remark);
                                jsonBuilder.put("bottomdiameter", bottomdiameter);
                                jsonBuilder.put("craterwallsdiameter", craterwallsdiameter);
                                jsonBuilder.put("craterdiameter", craterdiameter);
                                jsonBuilder.put("depositthickness", depositthickness);
                                jsonBuilder.put("extends7", urlArr);
                                jsonBuilder.put("createUser", SPUtil.get("userId", ""));
                                MyHttpClient
                                        .newBuilder()
                                        .post()
                                        .url(Api.HDD_WY_CRATERS)
                                        .addParam(jsonBuilder.toJsonString())
                                        .build()
                                        .enqueue(new BaseCallBack<LoginBean>() {
                                            @Override
                                            public void onSuccess(LoginBean bean) {
                                                super.onSuccess(bean);
                                                if (bean.getCode() == 200) {
                                                    if (-1 != _id && null != createrDbEntity) {
                                                        try {
                                                            daoSession.delete(createrDbEntity);
                                                        } catch (Exception e) {
                                                            e.printStackTrace();
                                                        }
                                                    }
                                                    CustomToast.showToast(CraterActivity.this, "提交成功");
                                                    finish();
                                                }
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                            }

                                            @Override
                                            public void onFailure(Call call, IOException e) {
                                                super.onFailure(call, e);
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                                CustomToast.showToast(CraterActivity.this, "网络异常");
                                            }

                                            @Override
                                            public void onError(int code) {
                                                super.onError(code);
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                                CustomToast.showToast(CraterActivity.this, "网络异常");
                                            }
                                        });
                            }
                        });
                    }
                }, "提交后不能再修改");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case HYImageUtils.REQUEST_CODE_FROM_CAMERA:
                List<Uri> list_1 = new ArrayList<>();
                list_1.add(HYImageUtils.imageUriFromCamera);
                photoRecycleBuild.updataAdapter(list_1);
                break;
            case HYImageUtils.REQUEST_CODE_FROM_ALBUM:
                ArrayList<String> files = data.getStringArrayListExtra("files");
                if (files == null || files.size() == 0) {
                    return;
                }
                List<Uri> list_2 = new ArrayList<>();
                for (String file : files) {
                    list_2.add(Uri.fromFile(new File(file)));
                }
                photoRecycleBuild.updataAdapter(list_2);
                // submitImage(list_2, correctTypeListEntity.getFieldList().get(lastClickItemPosition));
                break;
        }
    }

    private void getHttpData(String type) {
        MyHttpClient
                .newBuilder()
                .get()
                .url(Api.HDD_WY_CRATERS_TYPE + type)
                .build()
                .enqueue(new BaseCallBack<FaultTypeBean>() {
                    @Override
                    public void onSuccess(FaultTypeBean bean) {
                        super.onSuccess(bean);
                        if (bean.getCode() == 200) {
                            setFaultTypeCVD(bean, type);
                        }
                        if (myDialog != null)
                            myDialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(CraterActivity.this, "网络异常");
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(CraterActivity.this, "网络异常");
                    }
                });
    }


    public void setFaultTypeCVD(FaultTypeBean bean, String type) {
        dataBeans.clear();
        dataBeans.addAll(bean.getData());
        String[] arr = new String[dataBeans.size()];
        for (int i = 0; i < dataBeans.size(); i++) {
            arr[i] = dataBeans.get(i).getDictItemName();
        }
        HYDialogUtils.showSingleChoiceItemAlertDialog(this, "选择", 0, arr
                , new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (type) {
                            case "CVD-16-Direction":
                                dataBean = dataBeans.get(i);
                                tvOverfalldirection.setText(dataBeans.get(i).getDictItemName());
                                break;
                        }
                        dialogInterface.dismiss();
                    }
                });
    }

    public void getDetailHttp() {
        if (myDialog == null) {
            myDialog = DialogUtils.showRefreshDialog(activity);
        } else {
            myDialog.show();
        }
        String url = Api.HDD_WY_CRATERS + "/" + uuid;
        MyHttpClient
                .newBuilder()
                .get()
                .url(url)
                .build()
                .enqueue(new BaseCallBack<CreaterEntity>() {
                    @Override
                    public void onSuccess(CreaterEntity bean) {
                        super.onSuccess(bean);
                        if (bean.getCode() == 200) {
                            setDetailData(bean);
                        }
                        if (myDialog != null)
                            myDialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(CraterActivity.this, "网络异常");
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(CraterActivity.this, "网络异常");
                    }
                });
    }

    private void setDetailData(CreaterEntity bean) {
        tabTitleBuilder.setDetailText(bean.getData().getProvince(), bean.getData().getCity()
                , bean.getData().getArea(), bean.getData().getLat(), bean.getData().getLon(), bean.getData().getTown());

        etId.setText(StringUtil.isNull(bean.getData().getId()));
        etConename.setText(StringUtil.isNull(bean.getData().getConename()));
        etConetype.setText(StringUtil.isNull(bean.getData().getConetype()));
        etConemorphology.setText(StringUtil.isNull(bean.getData().getConemorphology()));
        etConeheight.setText(StringUtil.isNull(bean.getData().getConeheight()));
        etCraterdepth.setText(StringUtil.isNull(bean.getData().getCraterdepth()));
        etInsideslopeangle.setText(StringUtil.isNull(bean.getData().getInsideslopeangle()));
        etOutsideslopeangle.setText(StringUtil.isNull(bean.getData().getOutsideslopeangle()));
        tvOverfalldirection.setText(StringUtil.isNull(bean.getData().getOverfalldirectionName()));
        etDeposittype.setText(StringUtil.isNull(bean.getData().getDeposittype()));
        etDepositgranularity.setText(StringUtil.isNull(bean.getData().getDepositgranularity()));
        etLavadribletsize.setText(StringUtil.isNull(bean.getData().getLavadribletsize()));
        etRockinclusiontype.setText(StringUtil.isNull(bean.getData().getRockinclusiontype()));
        etRockinclusionnum.setText(StringUtil.isNull(bean.getData().getRockinclusionnum()));
        etRockinclusiongranularity.setText(StringUtil.isNull(bean.getData().getRockinclusiongranularity()));
        etRockinclusionshape.setText(StringUtil.isNull(bean.getData().getRockinclusionshape()));
        etRockinclusionoutputstate.setText(StringUtil.isNull(bean.getData().getRockinclusionoutputstate()));
        etPhotoAiid.setText(StringUtil.isNull(bean.getData().getPhotoAiid()));
        etPhotodescArwid.setText(StringUtil.isNull(bean.getData().getPhotodescArwid()));
        etPhotographer.setText(StringUtil.isNull(bean.getData().getPhotographer()));
        etRemark.setText(StringUtil.isNull(bean.getData().getCommentInfo()));
        etBottomdiameter.setText(StringUtil.isNull(bean.getData().getBottomdiameter()));
        etCraterwallsdiameter.setText(StringUtil.isNull(bean.getData().getCraterwallsdiameter()));
        etCraterdiameter.setText(StringUtil.isNull(bean.getData().getCraterdiameter()));
        etDepositthickness.setText(StringUtil.isNull(bean.getData().getDepositthickness()));
        photoRecycleBuild.setHttpUrl(bean.getData().getExtends7());
    }

    private CreaterDbEntity createrDbEntity;

    private void setDetail(CreaterDbEntity bean) {
        this.createrDbEntity = bean;
        tabTitleBuilder.setDetailText(bean.getProvince(), bean.getCity()
                , bean.getArea(), bean.getLat(),bean.getLon(), bean.getTown());

        etId.setText(StringUtil.isNull(bean.getId()));
        etConename.setText(StringUtil.isNull(bean.getConename()));
        etConetype.setText(StringUtil.isNull(bean.getConetype()));
        etConemorphology.setText(StringUtil.isNull(bean.getConemorphology()));
        etConeheight.setText(StringUtil.isNull(bean.getConeheight()));
        etCraterdepth.setText(StringUtil.isNull(bean.getCraterdepth()));
        etInsideslopeangle.setText(StringUtil.isNull(bean.getInsideslopeangle()));
        etOutsideslopeangle.setText(StringUtil.isNull(bean.getOutsideslopeangle()));
        tvOverfalldirection.setText(StringUtil.isNull(bean.getOverfalldirectionName()));
        etDeposittype.setText(StringUtil.isNull(bean.getDeposittype()));
        etDepositgranularity.setText(StringUtil.isNull(bean.getDepositgranularity()));
        etLavadribletsize.setText(StringUtil.isNull(bean.getLavadribletsize()));
        etRockinclusiontype.setText(StringUtil.isNull(bean.getRockinclusiontype()));
        etRockinclusionnum.setText(StringUtil.isNull(bean.getRockinclusionnum()));
        etRockinclusiongranularity.setText(StringUtil.isNull(bean.getRockinclusiongranularity()));
        etRockinclusionshape.setText(StringUtil.isNull(bean.getRockinclusionshape()));
        etRockinclusionoutputstate.setText(StringUtil.isNull(bean.getRockinclusionoutputstate()));
        etPhotoAiid.setText(StringUtil.isNull(bean.getPhotoAiid()));
        etPhotodescArwid.setText(StringUtil.isNull(bean.getPhotodescArwid()));
        etPhotographer.setText(StringUtil.isNull(bean.getPhotographer()));
        etRemark.setText(StringUtil.isNull(bean.getCommentInfo()));
        etBottomdiameter.setText(StringUtil.isNull(bean.getBottomdiameter()));
        etCraterwallsdiameter.setText(StringUtil.isNull(bean.getCraterwallsdiameter()));
        etCraterdiameter.setText(StringUtil.isNull(bean.getCraterdiameter()));
        etDepositthickness.setText(StringUtil.isNull(bean.getDepositthickness()));
        if (!TextUtils.isEmpty(bean.getExtends7())) {
            String[] arr = bean.getExtends7().split(",");
            List<Uri> list = new ArrayList<>();
            for (int i = 0; i < arr.length; i++) {
                File file = new File(arr[i]);
                Uri uri = Uri.fromFile(file);
                list.add(uri);
            }
            photoRecycleBuild.updataAdapter(list);
        }
    }
}
